interface AbstractIterator {
    next(): any
    hasNext(): boolean
    remove(): boolean
    resetCursor(): void
}

class SpecificIterator implements AbstractIterator {
    private propertyList: Array<any>
    private cursor: number = 0

    constructor(propertyList: Array<any>) {
        this.propertyList = propertyList
    }
    resetCursor(): void {
        this.cursor = 0
    }

    public next(): any {
        return this.hasNext() ? this.propertyList[this.cursor++] : null
    }

    public hasNext(): boolean {
        return this.cursor < this.propertyList.length
    }

    public remove(): boolean {
        this.propertyList.splice(this.cursor--, 1);
        return true
    }
}

interface Property {
    add(value: any): void
    remove(value: any): void
    createIterator(): AbstractIterator
}

class ConcreateProperty implements Property {
    //存放实体对象的容器
    private propertyList: Array<any>
    constructor() {
        this.propertyList = new Array<any>
    }

    add(value: any): void {
        this.propertyList.push(value)
    }

    remove(value: any): void {
        const removeIndex = this.propertyList.findIndex((listValue) => {
            return listValue === value
        })

        this.propertyList.splice(removeIndex, 1)
    }
    createIterator(): AbstractIterator {
        return new SpecificIterator(this.propertyList)
    }
}

const IteratorTest = (): void => {
    const property : Property = new ConcreateProperty()
    property.add("属性1")
    property.add("属性2")
    property.add("属性3")
    const iterator : AbstractIterator = property.createIterator()
    while(iterator.hasNext()){
        console.log(iterator.next());
    }


    iterator.resetCursor()
    property.remove("属性2")
    console.log("删除属性2");
    while(iterator.hasNext()){
        console.log(iterator.next());
    }

}

IteratorTest()